﻿// See https://aka.ms/new-console-template for more information

static void Moving(int x,char Tower1,char Tower2,char Tower3)
{
    //如果只有一个盘子直接由A到B,如果有x个盘子则当x=1时退出递归
    if (x == 1)
        Move(x,Tower1, Tower3);
    else
    {
        //将（x-1）个盘子看成一个整体，从A经过B移动到C
        Moving(x - 1, Tower1, Tower3, Tower2);
        //将第x个盘子由A移动到B
        Move(x, Tower1, Tower3);
        //将（x-1）个盘子看成一个整体，从C经过A移动到B
        Moving(x - 1, Tower2, Tower1, Tower3);
    }
}
//定义移动的函数
 static void Move(int y,char Tower1,char Tower3)
{
    Console.WriteLine($"将{y}号盘子从{Tower1}移到{Tower3}");
}
Console.WriteLine("请输入A上盘子的个数：");
//将输入的数字转换类型为整型
int n=Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"将{n}个盘子从A移到B的步骤是：");
Moving(n, 'A', 'C', 'B');


